package org.lixf.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.lixf.beans.Student;
import org.lixf.services.IStudentService;
import org.lixf.services.StudentServiceImpl;

public class LoginServlet extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String num = request.getParameter("num");
		String passwrod = request.getParameter("password");
		HttpSession session = request.getSession();
		if (num == null || "".equals(num.trim())) {
			session.setAttribute("message", "学号不能为空");
			response.sendRedirect(request.getContextPath() + "/login.jsp");
			return;
		}

		// 需要使用new创建对象->spring
		IStudentService studentService = new StudentServiceImpl();
		Student student = studentService.checkUser(num, passwrod);
		if (student == null) {
			session.setAttribute("message", "学号或密码错误");
			response.sendRedirect(request.getContextPath() + "/login.jsp");
			return;
		}
	}

}
